/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.sesame.domain.Album;
import com.sesame.domain.AlbumTag;
import com.sesame.domain.Collect;
import com.sesame.domain.ImageTag;
import com.sesame.service.AlbumService;
import com.sesame.service.UserService;

/**
 * @author voidman
 * 
 */
public class CollectImageController extends AbstractController {

    private UserService userService;

    private AlbumService albumService;
    private Collect collect;

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public void setAlbumService(AlbumService albumService) {
        this.albumService = albumService;
    }

    public void setCollect(Collect collect) {
        this.collect = collect;
    }

    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        Integer imageId = Integer.parseInt(request.getParameter("imageId"));
        String url = request.getParameter("url");
        Integer userId = (Integer) request.getSession().getAttribute("userId");
        collect.setImageId(imageId);
        collect.setUserId(userId);
        collect.setUrl(url);
        Date createTime = new Date();
        collect.setCreateTime(createTime);
        userService.newCollect(collect);

        return new ModelAndView("redirect:" + request.getHeader("referer"));

    }

}